package com.lwb.ztx.user.model;

import android.content.Context;

import com.lwb.ztx.database.GreenDaoManager;
import com.lwb.ztx.database.greendao.dao.CollectDao;
import com.lwb.ztx.database.greendao.db.Collect;

import java.util.List;

/**
 * Created by luweibin on 2016/6/1.
 */
public class CollectModelImpl implements CollectModel {
    private OnCollectsLoadFinishListener listener;

    public CollectModelImpl(OnCollectsLoadFinishListener listener) {
        this.listener = listener;
    }

    @Override
    public void loadCollect(Context context) {
        CollectDao dao = GreenDaoManager.getDaoSession(context).getCollectDao();
        if(listener != null) {
            listener.onSuccess(dao.loadAll());
        }
    }

    @Override
    public void deleteCollects(Context context,List<Collect> collectList) {
        CollectDao dao = GreenDaoManager.getDaoSession(context).getCollectDao();
        dao.deleteInTx(collectList);
        this.loadCollect(context);
    }

    public interface OnCollectsLoadFinishListener {
        void onSuccess(List<Collect> collectList);
    }

}
